﻿var XmlHttp;
function getXmlHttp() {
    try {
        //Neu la trinh duyet Firefox, Opera 8.0 +, Safari  
        XmlHttp = new XMLHttpRequest();
    }
    catch (e1) {
        // Neu la Internet Explorer 6.0+
        try {
            XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e2) {
            try {
                //Neu la Internet Explorer 5.0+
                XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e3) {
                alert("Trinh duyet cua ban khong ho tro Ajax (Your browser does not support Ajax)");
                return false;
            }
        }
    }
}
function HandleResponse() {
    if (XmlHttp.readyState == 4) {
        if (XmlHttp.status == 200) {
            ClearAndSetState(XmlHttp.responseText);

        }
        else {

            alert("Yeu cau cau ban khong thuc hien duoc");
        }
    }
}
function ClearAndSetState(text) {
    document.getElementById("list").innerHTML = text;
}
function Loading() {
    document.getElementById("loading").style.display = 'block';
}
function Clear() {
    document.getElementById("loading").style.display = 'none';
}

/*----------------------------    */
function Search() {
    var rq = Math.random();
    var Name = document.getElementById("keyword1");

    if (Name.value != "") {
        var requestUrl = 'Ajax.aspx?menu=search&prodName=' + encodeURIComponent(Name.value) + "&rq" + rq;
        getXmlHttp();
        if (XmlHttp) {
            XmlHttp.onreadystatechange = HandleResponse;
            XmlHttp.open("GET", requestUrl, true);
            XmlHttp.send(null);
        }
    }
}
function GetObjectsById(id) {
    var requestUrl;
    requestUrl = "Ajax.aspx?" + id;
    getXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}
function GetObjectNewsById(id) {
    var requestUrl;
    requestUrl = "Ajax.aspx?/hoa-hoc-1/" + id;
    getXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}
function SearchPro(str) {
    var s = document.getElementById(str).value;
    var rq = Math.random();
    var requestUrl;
    requestUrl = "Ajax.aspx?menu=search&key=" + s + "&rq=" + rq;
    getXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}
function GetObjectLinhVById(id) {
    var rq = Math.random();
    var requestUrl;
    requestUrl = "Ajax.aspx?menu=lvm&id=" + id + "&rq=" + rq;
    getXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}
function GetObjectTDById(id) {
    var rq = Math.random();
    var requestUrl;
    requestUrl = "Ajax.aspx?menu=tdM&id=" + id + "&rq=" + rq;
    getXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}
function PageIndex(menu, subCate, p) {
    var requestUrl;
    requestUrl = "Ajax.aspx?menu=" + menu + "&p=" + p + "&idsubcat=" + subCate;
    getXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}

function GetRegister(register) {

    var rq = Math.random();
    var requestUrl;
    requestUrl = "Ajax.aspx?/" + encodeURIComponent(register);
    getXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}
function GetListProductBySubCat(idCatSub) {
    var requestUrl;
    requestUrl = "Ajax.aspx?menu=sp&idsubcat=" + idCatSub;
    getXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}
function GetListProductByCat(idCat) {
    var rq = Math.random();
    var requestUrl;
    requestUrl = "Ajax.aspx?menu=sp&idcat=" + idCat + "&rq=" + rq;
    getXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}
function GetListCat(tabid, cat, page) {
    var requestUrl;
    requestUrl = "Ajax.aspx?tabid=" + encodeURIComponent(tabid) + "&cat=" + encodeURIComponent(cat) + "&page=" + encodeURIComponent(page);
    getXmlHttp();
    if (XmlHttp) {
        Loading();
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}

function GetProduct(tabid, cat, tab) {
    var rq = Math.random();
    var requestUrl;
    requestUrl = "Ajax.aspx?tabid=" + encodeURIComponent(tabid) + "&cat=" + encodeURIComponent(cat) + "&tab=" + tab + "&rq=" + rq;
    getXmlHttp();
    if (XmlHttp) {
        Loading();
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}

function clearAll_Click() {
    var numItems = document.forms[0].numItems.value;
    var check;
    for (var i = 1; i <= numItems; i++) {
        check = document.forms[0].item("check" + i);
        if (check.checked)
            check.click();
    }
}
function TestLogin(idProduct) {
    var frm = document;
    var Email = ""; var pass = ""; var cbRemove = ""; var txtQty = "";
    var rq = Math.random();
    var requestUrl;
    Email = frm.getElementById("txtUserName").value;
    Pass = frm.getElementById("txtPass").value;
    requestUrl = "Ajax.aspx?cat=9&UserName=" + Email + "&Pass=" + Pass + "&rq=" + rq;
    getXmlHttp();
    if (XmlHttp) {
        Loading();
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}
function OpenWindow(theUrl, winName, features) {
    window.open(theUrl + "&totalprice=ian3r9n03hltfa", winName, "width = 600px, height =650px, help=no, scroll=yes, status=no");
}
function OpenWindowUploadFile(theUrl, winName, features) {
    window.open(theUrl, winName, "width = 850px, height =650px, help=no, scroll=yes, status=no");
}
function UploadHinh(txtImage, img, path) {
    window.opener.document.getElementById(txtImage).value = path;
    window.opener.document.getElementById(img).src = path;
    window.close(); window.history.go(1);
}
function resetDev() {
    document.getElementById('inPutDevToCart').style.display = "none";
    document.getElementById('DevSubmit').style.display = "none";
}
function check_Click(id, id1234) {
    var id1 = "A_" + id; var id2 = "B_" + id; var id3 = "C_" + id; var id4 = "D_" + id;
    switch (id1234) {
        case id1:
            document.getElementById(id1).checked = true;
            document.getElementById(id2).checked = false;
            document.getElementById(id3).checked = false;
            document.getElementById(id4).checked = false;
            break;
        case id2:

            document.getElementById(id1).checked = false;
            document.getElementById(id2).checked = true;
            document.getElementById(id3).checked = false;
            document.getElementById(id4).checked = false;

            break;
        case id3:
            document.getElementById(id1).checked = false;
            document.getElementById(id2).checked = false;
            document.getElementById(id3).checked = true;
            document.getElementById(id4).checked = false;

            break;
        case id4:
            document.getElementById(id1).checked = false;
            document.getElementById(id2).checked = false;
            document.getElementById(id3).checked = false;
            document.getElementById(id4).checked = true;

            break;
    }
}
function SearchAdvance(id) {
    //    var rq = Math.random();
   
    var keyWord22 = document.getElementById("Text1").value;
    var keyWord21 = document.getElementById("ddlLinhVuc").value;
    alert(keyWord21);
    var requestUrl = 'Ajax.aspx?/search/' + keyWord22.value ;
    getXmlHttp();
    if (XmlHttp) {
        Loading();
        XmlHttp.onreadystatechange = HandleResponse;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send(null);
    }
}